package com.yiwei.zhh.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.ImageView;

/**
 * Created by xsooy-pc on 2017/7/27.
 */

public class RoundCornerImageView extends ImageView {
    private RectF rectf;
    private Path clipPath;

    public RoundCornerImageView(Context context) {
        super(context, null);
    }

    public RoundCornerImageView(Context context, AttributeSet attrs) {
        super(context, attrs, 0);

    }

    public RoundCornerImageView(Context context, AttributeSet attrs,
                                int defStyle) {
        super(context, attrs, defStyle);
        clipPath = new Path();
        rectf = new RectF();
    }

    @Override
    protected void onDraw(Canvas canvas) {

        int w = this.getWidth();
        int h = this.getHeight();
        rectf.set(0, 0, w, h);
        clipPath.addRoundRect(rectf, 10.0f, 10.0f, Path.Direction.CW);
        canvas.clipPath(clipPath);
        super.onDraw(canvas);
    }
}
